<?php

namespace common\repositories\cms;

use common\repositories\BaseRepository;
use common\entities\cms\DirEntity;

class DirRepository extends BaseRepository {

    static protected $handler;

    public function __construct($config = []) {
        self::$handler = new DirEntity();
        parent::__construct($config);
    }

    public function getDirList($where) {
        return self::$handler->getDirList($where);
    }

    public function getDirById($id){
        return DirEntity::find()
            ->where(['id'=>$id])
            ->one();
    }

    public function existsDir($id){
        return DirEntity::find()
            ->where(['parent_id'=>$id])
            ->exists();
    }

    /**
     *
     * @param $id 文章id
     * @param $status 显示状态
     * @return bool
     */
    public function displaySet($id, $status)
    {
        $dirEntity = DirEntity::find()->where(['id' => $id])->one();
        if (empty($dirEntity)) {
            return false;
        }
        $dirEntity->external_display = $status;
        return $dirEntity->save();
    }

    /**
     * 获取更新墙目录
     * @return array 返回更新墙目录
     */
    public function getUpdateDirIds()
    {
        $updateDirIds = DirEntity::find()->where(['parent_id'=> 99987])->select("id")->asArray()->all();
        if (empty($updateDirIds)){
            \Yii::error("没有取到更新墙目录");
        }
        return $updateDirIds;
    }
}
